﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    [ObjectEvent]
    public class RM_003EffectEvent : ObjectEvent<RM_003Effect>, IAwake
    {
        public void Awake()
        {
            Get().Awake();
        }
    }

    public class RM_003Effect : BattleEventComponent
    {
        public override BattleEventType[] EventType { get; set; } = new BattleEventType[] { BattleEventType.HpChange,BattleEventType.FightEnd };

        public override async Task RunEvent(BattleEventType eventType, FightModel fightModel, params object[] param)
        {
            DamageInfo damageInfo = param[0] as DamageInfo;
            //BattleCard battleCard = (param[0] as DamageInfo).AttackCard;
            if (eventType == BattleEventType.HpChange)
            {
                if (damageInfo.AttackCard.Owner != damageInfo.Reciver && damageInfo.DamageValue > 0 && damageInfo.CanBePrevent)
                {
                    Log.Debug($"{damageInfo.AttackCard.CardName}造成的{damageInfo.DamageType}伤害被防止了");
                    damageInfo.DamageValue = 0;
                }
            }
            if (eventType == BattleEventType.FightEnd)
            {
                BattleCard basecard = GetEntity<BattleCard>();
                basecard.RemoveComponent<RM_003Effect>();//伤害计算完后，移出对卡的debuff
            }
        }
    }
}
